package com.example.hospitalbakcends.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.hospitalbakcends.domain.Diagnosis;
import com.example.hospitalbakcends.domain.request.DiagnosisRequest;
import com.example.hospitalbakcends.service.DiagnosisService;
import jakarta.annotation.Resource;

import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/Diagnosis")
public class DiagnosisController {
    @Resource
    private DiagnosisService diagnosisService;

    /**
     * 生成一个病历（预约）
     * @param diagnosisRequest
     * @return
     * ps:保存预约表和最后诊断表合在一起，根据是否诊断的判定字段isCheck,0为未诊断（预约表状态），1为已诊断（病例表状态）
     */
    @PostMapping("/createDig")
    public boolean createDiagnosis(@RequestBody DiagnosisRequest diagnosisRequest){
        if (diagnosisRequest==null){
            return false;
        }
        return  diagnosisService.createDignosis(diagnosisRequest);
    }

    /**
     * 根据患者病历单查询
     * @param patientId 患者身份证号码
     * @param patientName 患者姓名
     * @return 病历单
     */
    @PostMapping("/patientDiagnosis")
    public List<Diagnosis> patientDiagnosis(@RequestBody Map<String,Object> map){
        String patientId = map.get("patientId").toString();
        String patientName = map.get("patientName").toString();
        if(patientId==null || patientName==null){
            return null;
        }
        String ID=patientId;
        String name=patientName;
        return diagnosisService.patientDiagnosis(ID,name);
    }
    @GetMapping("/getAllreserve")
    public List<Diagnosis> getAllDiagnosis(){
        QueryWrapper diagnosisQueryWrapper = new QueryWrapper();
        diagnosisQueryWrapper.eq("isCheck",0);
        return diagnosisService.list(diagnosisQueryWrapper);
    }
    /**
     * 根据医生姓名查询病历单
     * @param doctorName 医生姓名
     * @return 病历单
     */
    @PostMapping("/doctorDiagnosis")
    public List<Diagnosis> doctorDiagnosis(@RequestBody Map<String,Object> map){
        String doctorName = map.get("doctorName").toString();
        System.out.println(doctorName);
        if(doctorName==null){
            return null;
        }
        return diagnosisService.getByDoctorName(doctorName);
    }

    /**
     * 根据医生姓名查询预约单
     * @param doctorName 医生姓名
     * @return
     */
    @PostMapping("/getBookDiagnosis")
    public List<Diagnosis> getBookDiagnosis(@RequestBody Map<String,Object> map){
        String doctorName = map.get("doctorName").toString();
        System.out.println(doctorName);
        if(doctorName==null){
            return null;
        }
        return diagnosisService.getBookDiagnosis(doctorName);
    }

    @PostMapping("/doDiagnosis")
    public boolean doDiagnosis(@RequestBody Map<String,Object> map){
        String patientId = map.get("patientId").toString();
        String medicines = map.get("medicines").toString();
        String price = map.get("price").toString();
        if(patientId==null || medicines==null || price==null){
            return false;
        }else{
            return diagnosisService.doDiagnosis(patientId,medicines,price);
        }
    }

}
